﻿using System;
using Microsoft.Phone.Shell;
using CCWP7.Model;
using System.Text;

namespace CCWP7.STA
{
    public class ShellTileDataService : IShellTileDataService
    {
        ShellTileData IShellTileDataService.GetShellTile(IProjectReport projectReport)
        {
            var data = new StandardTileData
            {
                BackgroundImage = GetBackgroundImageUri(projectReport.LastBuildStatus),
                Title = projectReport.Name,
                BackTitle = DateTime.Now.ToShortTimeString(),// projectReport.Name,
                BackContent = GetStatus(projectReport),
            };

            return data;
        }

        string GetStatus(IProjectReport projectReport)
        {
            var stringBuilder = new StringBuilder();

            //stringBuilder.AppendLine(projectReport.Name);
            stringBuilder.AppendLine(projectReport.Activity);
            stringBuilder.AppendLine(projectReport.LastBuildStatus);
            //stringBuilder.AppendLine(projectReport.LastBuildTime.ToString());

            return stringBuilder.ToString();
        }

        Uri GetBackgroundImageUri(string lastBuildStatus)
        {
            switch (lastBuildStatus)
            {
                case "Success":
                    return new Uri("/Images/Green.Background.png", UriKind.Relative);
                case "Failure":
                case "Exception":
                    return new Uri("/Images/Red.Background.png", UriKind.Relative);
                case "Cancelled":
                case "Unknown":
                default:
                    return new Uri("/Images/Gray.Background.png", UriKind.Relative);
            }

        }
    }
}
